package com.kalaqia.image.di.module;

import android.support.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.kalaqia.image.GlideLoader;
import com.kalaqia.image.library.IImageLoaderStrategy;
import com.kalaqia.image.library.ImageLoaderManager;
import com.kalaqia.image.library.ImageLoaderOptions;
import com.kalaqia.image.library.ImageType;

import dagger.Module;
import dagger.Provides;

/**
 * function:
 * project:kalaqia
 * describe:
 * created owner:kalaqia 421407393@qq.com
 * created date:2017/8/4 14:15
 */
//<editor-fold desc="version update log">
// update owner:kalaqia  421407393@qq.com
// update datetime:2017/8/4 14:15
// update remark:
//</editor-fold>
@Module
public class GlideModule {

    private ImageLoaderOptions options;

    public GlideModule(@NonNull ImageLoaderOptions options) {
        this.options = options;
    }

    @Provides
    public ImageLoaderOptions provideImageLoaderOptions() {
        return this.options;
    }

    @Provides
    public RequestManager providerRequestManager(IImageLoaderStrategy loaderStrategy) {
        return ((GlideLoader) loaderStrategy).buildRequestManager(this.options);
    }

    @Provides
    public RequestBuilder providerBuilder(RequestManager manager) {
        if (options.getImageType() == ImageType.TYPE_BITMAP) {
            return manager.asBitmap().load(options.getUrl());
        } else {
            return manager.load(options.getUrl());
        }
    }

    @Provides
    public IImageLoaderStrategy provideIImageLoaderStrategy() {
        return new GlideLoader();
    }


}
